#include "GameObject.h"
#include "../Managers/GameManager.h"
#include "../Maps/Forest.h"
#include "../Maps/MapCell.h"

GameObject::GameObject(const Vec2i &pos, int tile, const TCODColor &color)
	: pos(pos), prev_pos(pos), tile(tile), color(color)
{
}

GameObject::~GameObject()
{
}

void GameObject::render()
{
	auto console = GameManager::getSingleton()->getMapConsole();
	console->putChar(prev_pos.x(), prev_pos.y(), ' ', TCOD_BKGND_NONE);
	console->putChar(pos.x(), pos.y(), tile, TCOD_BKGND_NONE);
	console->setCharForeground(pos.x(), pos.y(), color);
}

void GameObject::translate(int dx, int dy)
{
	prev_pos = pos; 
	pos.x() += dx; 
	pos.y() += dy;
	auto forest = GameManager::getSingleton()->getForest();
	if(pos.x() <= 0.0f || pos.y() <= 0.0f || pos.x() >= forest->getMapSize().x() || pos.y() >= forest->getMapSize().y())
	{
		pos = prev_pos;
		return;
	}

	auto fov = forest->getFOV();
	if(fov->isWalkable(pos.x(), pos.y()) == false)
		pos = prev_pos;
}
